# -*- coding: utf-8 -*-

# File Name： plot_route
# Description :
# Author : lirui
# create_date： 2022/6/1
# Change Activity:
"""
绘制路径图
"""
from matplotlib import pyplot as plt


def draw_route(p1, p2, ax):
    ax.annotate("", xy=(p2[0], p2[1]), xytext=(p1[0], p1[1]), arrowprops=dict(arrowstyle="->", color="r"))
    plt.scatter(p1[0], p1[1])
    plt.scatter(p2[0], p2[1])
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.grid()
    ax.set_aspect('equal')


def plot_tsp_routes(points, sort_points):
    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot()
    points_size = len(sort_points)
    for i in range(points_size - 1):
        p1 = points[i]
        p2 = points[i + 1]
        draw_route(p1, p2, ax)
    p1 = points[points_size - 1]
    p2 = points[0]
    draw_route(p1, p2, ax)
    fig.savefig('1.jpg')
